package com.oocl.o2o.client.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.oocl.o2o.client.dao.MerchantDao;
import com.oocl.o2o.client.entity.Merchant;
import com.oocl.o2o.client.service.MerchantService;
import com.oocl.o2o.client.util.ConfigBaseUtil;
import com.oocl.o2o.connectutil.dto.FeedBackStatusToCDTO;
import com.oocl.o2o.connectutil.util.GetWhiteStatusUtil;

@Service
public class MerchantServiceImpl implements MerchantService {
	
	@Resource(name="merchantDaoImpl")
	private MerchantDao merchantDao;
	@Override
	public Merchant add(Merchant t) {
		// TODO Auto-generated method stub
		return merchantDao.add(t);
	}

	@Override
	public Merchant update(Merchant t) {
		// TODO Auto-generated method stub
		return merchantDao.update(t);
	}

	@Override
	public Merchant delete(String id) {
		// TODO Auto-generated method stub
		return merchantDao.delete(id);
	}

	@Override
	public Merchant findById(String id) {
		Merchant merchant = merchantDao.findById(id);
		merchant.setPortrait(ConfigBaseUtil.getPropertiesInfo("imgPrefix")+merchant.getPortrait());
		return merchant;
	}

	@Override
	public List<Merchant> findAll() {
		// TODO Auto-generated method stub
		return merchantDao.findAll();
	}

	@Override
	public Merchant findByUsername(String username) {
		Merchant merchant = merchantDao.findByUsername(username);
		merchant.setPortrait(ConfigBaseUtil.getPropertiesInfo("imgPrefix")+merchant.getPortrait());
		return merchant;
	}

	@Override
	public List<Merchant> getAllPassMerchantsFromA() {
		try {
		
			List<FeedBackStatusToCDTO> merchantsBackStatusToCDTOs = GetWhiteStatusUtil.receive();  //实际代码
			List<Merchant> merchants = new ArrayList<Merchant>();
			for(FeedBackStatusToCDTO dto:merchantsBackStatusToCDTOs){
				Merchant merchant = merchantDao.findByUsername(dto.getUname());
				merchant.setPortrait(ConfigBaseUtil.getPropertiesInfo("imgPrefix")+merchant.getPortrait());
				System.out.println("根据白名单的名字从数据库中查询出来的信息为： "+merchant.toString());
				
				merchants.add(merchant);
			}
			return merchants;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
